#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <pthread.h>
#include "PerfDevil.hpp"
#include "EzImage.hpp"

using std::cout;
using std::endl;

#ifdef _WIN32
#include <windows.h>
#elif MACOS
#include <sys/param.h>
#include <sys/sysctl.h>
#else
#include <unistd.h>
#endif

// peut etre utile pour lancer le nombre de threads adéquat
unsigned coeurs(){
#ifdef WIN32
    SYSTEM_INFO sysinfo;
    GetSystemInfo(&sysinfo);
    return sysinfo.dwNumberOfProcessors;
#elif MACOS
    int n[2];
    unsigned taille = 4;
    uint32_t cpt;

    n[0] = CTL_HW;
    n[1] = HW_AVAILCPU;
    sysctl(n, 2, &cpt, &taille, NULL, 0);

    if(count < 1){
        n[1] = HW_NCPU;
        sysctl(n, 2, &cpt, &taille, NULL, 0);
        if(cpt < 1){
        	cpt = 1;
        }
    }
    return cpt;
#else
    return sysconf(_SC_NPROCESSORS_ONLN);
#endif
}

pthread_t *threads = new pthread_t[coeurs()];

void init_devil(){
    ilInit();
    iluInit();
}

void quit_devil(){
    ilShutDown();
}


int main(){

    srand(time(NULL));

    init_devil();

    EzImage *img = new EzImage("../img/cman.jpg");

//    cout << "Temps d'exécution: " << PerfDevil::temps_execution_iluBlurAvg(15) << "s" << endl;

    img->flou(3);
    img->sauvegarder_image("flou.jpg");
    img->negative();
    img->sauvegarder_image("negative.jpg");
    img->edge_detect();
    img->sauvegarder_image("edge_detect.jpg");

    if(img){
    	delete img;
    	img = NULL;
    }

    quit_devil();

	if(threads){
		delete[] threads;
		threads = NULL;
	}

    return 0;
}






